/**
 * 
 */
package com.whu.waterworks.action;

import java.util.ArrayList;
import java.util.List;


import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.whu.waterworks.model.WaterPlant;
import com.whu.waterworks.service.WaterPlantService;

/**
 * @author： Joymin
 * @date：2016-3-14 下午8:56:57
 * 说明: 
 */
public class WaterPlantAction extends ActionSupport{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private  WaterPlantService  waterPlantService;
	private  WaterPlant waterPlant;
	private  List<WaterPlant> rsWaterPlant;
	private  String jonsStrOfName;
	private  String code;
	
	
	
	@SuppressWarnings("finally")
	public String addWaterPlant(){		
		String message="";
		ActionContext ctx = ActionContext.getContext();
		try{
			message=waterPlantService.addwaterPlant(waterPlant);			
		}catch(Exception e){
			e.printStackTrace();
			message="提交失败，请稍后！";
			return message;
		}finally{
			System.out.println(message);			
			ctx.put("message", message);//往request里放入req
			ctx.put("urladdress", "./systemManage/addWaterPlant.jsp");//往request里放入req	
			return SUCCESS;  
		}	
	}
	
	

	/**
	 * @action 
	 */
	public String getAllWaterPlant(){
		System.out.println("getAllwaterPlant start");
		try{
			rsWaterPlant=new ArrayList<WaterPlant>();
			rsWaterPlant=waterPlantService.getAllWaterPlants();			
			return SUCCESS;
		}catch(Exception e){
			e.printStackTrace();
			return "exception";
		}finally{			    	
			System.out.println("getAllwaterPlant end");		
		}
	}
	
	/**
	 * @action 
	 */
	public String getWaterPlantByCode(){		
		System.out.println("getwaterPlantById start");		
		try{
			System.out.println("code="+code);
			waterPlant=waterPlantService.getWaterPlantById(code);			
  	  		return SUCCESS;
		}catch(Exception e){
			e.printStackTrace();
			return "exception";
		}finally{
			System.out.println("getAllwaterPlant end");
		} 
	}


	/**
	 * @action 
	 */
	public String getWaterPlantOfMaxCode(){
		System.out.println("getwaterPlantById start");		
		waterPlant=waterPlantService.getWaterPlantOfMaxCode();
		System.out.println("getwaterPlantOfLast end");
		return SUCCESS;
	}
	
	/**
	 * @action 
	 */
	public String getInitDataOfwaterPlant(){
		 System.out.println("getwaterPlantName start");
		 try{
   			jonsStrOfName=waterPlantService.getInitDataOfwaterPlant();
   			return SUCCESS;
 		 }catch(Exception e){
 			e.printStackTrace();
 			return "exception";
 		 }finally{
 			System.out.println("jonsStrOfName="+jonsStrOfName);
 			System.out.println("getInitDataOfwaterPlant end");
 		 }
	}
	
	public String delWaterPlant(){		
		 System.out.println("delWaterPlant start");		
		 String message="";
		 ActionContext ctx = ActionContext.getContext();
		 try{    		   	
   		     message=waterPlantService.delWaterPlant(waterPlant);
   		     ctx.put("message", message);//往request里放入req
 		     ctx.put("urladdress", "./systemManage/addWaterPlant.jsp");//往request里放入req
   		     return SUCCESS;
		  }catch(Exception e){
			   e.printStackTrace();
			   return "exception";
		  }finally{
			   System.out.println("delWaterPlant end");		
		  }	
	}
	
	
	public String getSelectOfWaterPlant(){
 		 System.out.println("getAllIrrBAWaterGateName start");
 		try{
 			jonsStrOfName=waterPlantService.getSelectOfWaterPlant();
 			return SUCCESS;
		 }catch(Exception e){
			e.printStackTrace();
			return "exception";
		 }finally{
			 System.out.println("jonsStrOfName="+jonsStrOfName);
			 System.out.println("getAllIrrBAWaterGateName end");			
		 }
 	}
	
	public WaterPlantService getWaterPlantService() {
		return waterPlantService;
	}
	public void setWaterPlantService(WaterPlantService waterPlantService) {
		this.waterPlantService = waterPlantService;
	}
	public WaterPlant getWaterPlant() {
		return waterPlant;
	}
	public void setWaterPlant(WaterPlant waterPlant) {
		this.waterPlant = waterPlant;
	}
	public List<WaterPlant> getRsWaterPlant() {
		return rsWaterPlant;
	}
	public void setRsWaterPlant(List<WaterPlant> rsWaterPlant) {
		this.rsWaterPlant = rsWaterPlant;
	}
	public String getJonsStrOfName() {
		return jonsStrOfName;
	}
	public void setJonsStrOfName(String jonsStrOfName) {
		this.jonsStrOfName = jonsStrOfName;
	}
	public String getCode() {
		return code;
	}
	public void setCode(String code) {
		this.code = code;
	}
}
